from time import sleep

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By

class UserInfoPage():

    def __init__(self,driver):
        # self.driver = webdriver.Chrome()
        self.driver = driver

    user_head_loc = (By.XPATH, '//*[@id="preview"]')
    select_loc = (By.XPATH, '//*[@id="filePicker2"]/div[2]/input')
    iframe_loc = (By.CSS_SELECTOR, '[id *="layui-layer-iframe"]')
    saveimg_loc = (By.CSS_SELECTOR, '[class="saveBtn"]')

    def upload_user_head_img(self, path):
        """
        上传用户头像
        :return:
        """
        self.driver.find_element(*self.user_head_loc).click()
        self.switch_into_frame()
        self.driver.find_element(*self.select_loc).send_keys(path)
        self.driver.find_element(*self.saveimg_loc).click()
        self.driver.switch_to.default_content()

    def switch_into_frame(self):
        sleep(1)
        self.driver.switch_to.frame(self.driver.find_element(*self.iframe_loc))
        sleep(1)


    # 获取指定对象的属性值
    def get_ele_attribute(self, attribute):
        value = self.driver.find_element(*self.user_head_loc).get_attribute(attribute)
        return value